<template id="child-Outmap">
  <div id="allmap" :style="style"></div>
</template>

<script>
  import tips_green from '../../assets/images/tips/tips_green.png'
  import tips_g from '../../assets/images/tips/tips_g.png'
  import tips_r from '../../assets/images/tips/tips_r.png'
  import tips_y from '../../assets/images/tips/tips_y.png'
  import show from '../../assets/images/show.png'
  export default{
    data(){
      return{
        style:{
          width:'100%',
          height:this.om.height+'px'
        },
        longitude:this.om.longitude,
        latitude:this.om.latitude,
        data_info:this.om.data_info,
        zoom:this.om.zoom
      }
    },
    props:['om'],    //通过props属性，将从父级得到的数据传给子级
    mounted:function(){
      this.initMap(this.data_info);
    },
    methods:{
      initMap: function(markers){
        var map = new BMap.Map("allmap");
        map.centerAndZoom(new BMap.Point(this.longitude, this.latitude), this.zoom);
        map.enableScrollWheelZoom();
        map.enableKeyboard();
        map.disableScrollWheelZoom();
        map.disableDoubleClickZoom();
        //向地图添加覆盖物
        for (var index = 0; index < markers.length; index++) {
          this.addMarker(markers[index],map);
        }
      },
      addMarker: function (item,map) {
        var othis = this;
        var myIcon = new BMap.Icon(this.imgSwitch(item.status), new BMap.Size(39, 25));
        var marker = new BMap.Marker(new window.BMap.Point(item.locationx, item.locationy), {icon: myIcon});
        marker.addEventListener("click", function () {
          console.log(item.id);
          othis.$router.push({
            path : '/main/subMain/'+item.id,
          });
        });
        if (item.status == '2') {
          marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
        }
        map.addOverlay(marker);
      },
      imgSwitch: function (status) {
        switch (status) {
          case '0' :
            return tips_green; //正常
          case '1' :
            return tips_y.png; //故障
          case '2' :
            return tips_r.png; //报警
          case '3' :
            return tips_g.png //未启用
        }
      },
      toSubIndex: function () {
        alert(1);
      }
    }
  }
</script>
